package com.zxhhyj.storm.common

import com.zxhhyj.storm.schema.Column
import com.zxhhyj.storm.schema.ColumnBuilder
import com.zxhhyj.storm.schema.Table

fun <T> unpacking(targetTable: Table<T>, entry: T): Map<String, *> {
    val map = targetTable.columns
        .mapNotNull {
            when (it) {
                is Column.RowBinding -> {
                    it.fieldName to it.selector.get(entry)
                }

                is ColumnBuilder -> {
                    null
                }
            }
        }
        .associate {
            it
        }
    return map
}

expect fun <T> packing(targetTable: Table<T>, selectColumns: List<Column<*, *>>, values: Map<String, *>): T